﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

using System.Xml.Serialization;

namespace nadModel
{
    public class SerializationHelper
    {
        public static string Serialize(object o, Type ty)
        {
            XmlSerializer serializer = new XmlSerializer(ty);
            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
            serializer.Serialize((TextWriter)writer, o);
            stream.Seek(0L, SeekOrigin.Begin);
            StreamReader reader = new StreamReader(stream, Encoding.UTF8);
            return reader.ReadToEnd();
        }

        // Methods
        public static object Deserialize(string xml, Type ty)
        {
            StringReader textReader = new StringReader(xml);
            XmlSerializer serializer = new XmlSerializer(ty);
            return serializer.Deserialize(textReader);
        }
    }
}
